package com.shadow.mall.order.remote.dubbo;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.shadow.mall.common.core.JsonResult;
import com.shadow.mall.order.exception.OrderBizException;
import com.shadow.mall.order.remote.RiskService;
import com.shadow.mall.order.remote.fallback.RiskRemoteFallback;
import com.shadow.mall.risk.api.RiskApi;
import com.shadow.mall.risk.domain.dto.CheckOrderRiskDTO;
import com.shadow.mall.risk.domain.request.CheckOrderRiskRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 营销服务远程接口
 *
 * @version 1.0
 */
@Component
public class RiskRemote {

    /**
     * 风控服务
     */
//    @Autowired
//    private RiskApi riskApi;

    @Autowired
    private RiskService riskService;

    /**
     * 订单风控检查
     * @param checkOrderRiskRequest
     * @return
     */
    @SentinelResource(value = "RiskRemote:checkOrderRisk",
            fallbackClass = RiskRemoteFallback.class,
            fallback = "checkOrderRiskFallback")
    public CheckOrderRiskDTO checkOrderRisk(CheckOrderRiskRequest checkOrderRiskRequest) {
        JsonResult<CheckOrderRiskDTO> jsonResult = riskService.checkOrderRisk(checkOrderRiskRequest);
        if (!jsonResult.getSuccess()) {
            throw new OrderBizException(jsonResult.getErrorCode(), jsonResult.getErrorMessage());
        }
        return jsonResult.getData();
    }

}